package com.itheima.sc.web.sms;

import com.itheima.sc.pojo.sms.HomeAdvertise;
import com.itheima.sc.result.Result;
import com.itheima.sc.service.sms.SmsHomeAdvertiseService;
import com.itheima.sc.vo.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/home/advertise")
public class SmsHomeAdvertiseController {

    @Autowired
    private SmsHomeAdvertiseService advertiseService;


    //添加广告
    @PostMapping("/create")
    public Result addAdvertise(@RequestBody HomeAdvertise advertise){
        advertiseService.addAdvertise(advertise);
        return Result.success(null);
    }
    //批量删除广告
    @PostMapping("/delete")
    public Result deleteAdvertise(@RequestParam List<Long> ids){
        advertiseService.deleteAdvertise(ids);
        return Result.success(null);
    }

    //查询广告列表
    @GetMapping("/list")
    public Result selectAdvertiseList(@RequestParam Map<String,String> param){
        PageResult pageResult=advertiseService.selectAdvertiseList(param);
        return Result.success(pageResult);
    }
    //修改广告的状态
    @PostMapping("/update/status/{id}")
    public Result updateAdvertiseStatus(@PathVariable("id")Long id,Integer status){
        advertiseService.updateAdvertiseStatus(id,status);
        return Result.success(null);
    }
    //修改广告数据
    @PostMapping("/update/{id}")
    public Result updateAdvertise(@PathVariable("id")Long id,@RequestBody HomeAdvertise advertise){
        advertiseService.updateAdvertise(id,advertise);
        return Result.success(null);
    }
    //查询广告详情
    @GetMapping("/{id}")
    public Result selectAdvertiseInfo(@PathVariable("id")Long id){
        HomeAdvertise advertise=advertiseService.selectAdvertiseInfo(id);
        return Result.success(advertise);
    }




}
